Coding For Beginners: A Simplified Guide For Beginners To Learn Self-Taught Coding Step By Step. Become An Expert Coder In The Shortest Time Possible by Gates Eugene

Coding For Beginners: A Simplified Guide For Beginners To Learn Self-Taught Coding Step By Step. Become An Expert Coder In The Shortest Time Possible by Gates Eugene

Author:Gates, Eugene [Gates, Eugene]
Language: eng
Format: epub
Published: 2020-08-18T16:00:00+00:00


//OK! Now, privateVariableOne = 21

}

In the above code stub, the following code represents the constructor -

ExampleClass(int publicVariableValue) {

//This is the constructor

publicVariableOne = publicVariableValue;

}

It takes in an integer and assigns its value to publicVariableOne.

To instantiate an object of the class where the value of publicVariableOne will be 30, we do the following:

ExampleClass object(30);

Now, there’s another way of instantiating values in the constructor: ExampleClass(int publicVariableValue):publicVariableOne(publicVariableValue) {

//This is the constructor

}

Example- Create a Dog class that stores a dog’s age and the name and has methods called bark and eat.

#include<iostream>

#include<string>

using namespace std;

class Dog {

private:

int age;

string name;

public:

Dog(int dogAge, string dogName) :age(dogAge), name(dogName) {}

void printDogName() {

cout << "Dog Name: " << name << endl;

}

void printDogAge() {

cout << "Dog Age: " << age << endl;

}

void bark() {

cout << "WOOOF WOOOOF!!" << endl;

}

void eat() {

cout << "I'm eating right now. Don't bother me!" << endl;

}

};

int main() {

Dog henryTheDog(2, "Henry");

henryTheDog.printDogName();

henryTheDog.printDogAge();

henryTheDog.bark();

henryTheDog.eat();

}

Here’s the output -

Dog Name: Henry

Dog Age: 2

WOOOF WOOOOF!!

I'm eating right now. Don't bother me!

Press any key to continue . . .



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Popular ebooks
Deep Learning with Python by François Chollet(12593)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(7791)
Grails in Action by Glen Smith Peter Ledbrook(7705)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6424)
Kotlin in Action by Dmitry Jemerov(5074)
WordPress Plugin Development Cookbook by Yannick Lefebvre(3855)
Mastering Azure Security by Mustafa Toroman and Tom Janetscheck(3337)
Learning React: Functional Web Development with React and Redux by Banks Alex & Porcello Eve(3092)
Mastering Bitcoin: Programming the Open Blockchain by Andreas M. Antonopoulos(2873)
The Art Of Deception by Kevin Mitnick(2613)
Drugs Unlimited by Mike Power(2475)
The Innovators: How a Group of Hackers, Geniuses, and Geeks Created the Digital Revolution by Walter Isaacson(2361)
Kali Linux - An Ethical Hacker's Cookbook: End-to-end penetration testing solutions by Sharma Himanshu(2317)
Writing for the Web: Creating Compelling Web Content Using Words, Pictures and Sound (Eva Spring's Library) by Lynda Felder(2267)
A Blueprint for Production-Ready Web Applications: Leverage industry best practices to create complete web apps with Python, TypeScript, and AWS by Dr. Philip Jones(2267)
SEO 2018: Learn search engine optimization with smart internet marketing strategies by Adam Clarke(2197)
JavaScript by Example by S Dani Akash(2141)
DarkMarket by Misha Glenny(2086)
Wireless Hacking 101 by Karina Astudillo(2082)
Hands-On Cybersecurity with Blockchain by Rajneesh Gupta(2003)